function Exit66Table(tableClassName, columnDetails) {
    this._tableClassName = tableClassName
    this._columnDetails = columnDetails;
    
    this._baseDiv = null;
    this._headerRow = null;
    this._tableDiv = null;
    this._tableBodyDiv = null;
    
    this._rbTop = null;
    this._rbContent = null;
    this._rbBot = null; 
    
    this._rowCount = 0;
    
    this._init();
}


Exit66Table.prototype._init = function() {
    
    this._baseDiv = document.createElement('div');
    this._baseDiv.style.display = 'block';
    this._baseDiv.className = this._tableClassName;

    this._rbTop = document.createElement('div');
    this._rbTop.className = 'rbtop';
    this._rbTop.appendChild(document.createElement('div'));
    this._baseDiv.appendChild(this._rbTop);
    
    this._rbContent = document.createElement('div');
    this._rbContent.className = 'rbcontent';
    this._baseDiv.appendChild(this._rbContent);
    
    this._headerRow = document.createElement('div');
    this._headerRow.className = 'tableHeader';
    this._rbContent.appendChild(this._headerRow);
    
    this._rbBot = document.createElement('div');
    this._rbBot.className = 'rbbot';
    this._rbBot.appendChild(document.createElement('div'));
    this._baseDiv.appendChild(this._rbBot);

    if (_SARISSA_IS_IE) {
        this._rbContent.style.overflow = 'auto';
    }
    else {
        this._rbContent.style.overflow = 'visible !important';
    }
    
    this._height = 0;
    
    this.clearAllRows();
}

Exit66Table.prototype.setHeight = function(height) {
    this._height = height;
    if (height != 0) {
        this._baseDiv.style.height = height;
        this._rbContent.style.height = height - 
            (this._rbTop.offsetHeight + this._rbBot.offsetHeight);

        this._setTableHeight();
    }
}

Exit66Table.prototype._setTableHeight = function() {
    if (this._height != 0) {
        this._tableBodyDiv.style.height = this._rbContent.offsetHeight -
            (this._headerRow.offsetHeight);
        this._tableBodyDiv.style.maxHeight = this._rbContent.offsetHeight -
            (this._headerRow.offsetHeight);
    }
}

Exit66Table.prototype.setHeader = function(headerDetails) {
    var col;
    
    for (i = 0; i < headerDetails.length; i++) {
        col = document.createElement('div');
        col.innerHTML = headerDetails[i];
        this._headerRow.appendChild(col);
    }
}

Exit66Table.prototype.clearAllRows = function() {
    if (this._tableDiv) {
        this._rbContent.removeChild(this._tableDiv);
    }
    this._tableDiv = document.createElement('table');
    this._tableDiv.style.width = '100%';
    this._tableBodyDiv = document.createElement('tbody');
    
    this._setTableHeight();
    
    if (this._height != 0) {
        try {
            this._tableBodyDiv.style.overflow = 'auto';
        }
        catch (e) {
        }
        this._tableBodyDiv.style.overflowX = 'hidden';
        this._tableBodyDiv.style.overflowY = 'scroll';
        this._tableDiv.style.width = '100%';
    }
            
    this._tableDiv.appendChild(this._tableBodyDiv);
    this._rbContent.appendChild(this._tableDiv);
    
    this._rowCount = 0;   
}

Exit66Table.prototype.addRow = function(columnValues, clickFunction, 
    className, highlightCellOnly) {
    this._rowCount++;
    var evenOdd = '';
        
    if (!highlightCellOnly)
        highlightCellOnly = false;
	    
    if (!className) {
        className = 'row';
        if (this._rowCount % 2) {
            evenOdd = 'Even';
        }
        else {
            evenOdd = 'Odd';
        }
    }
    var row = document.createElement('tr');
    row.className = className + evenOdd;
    row.style.height = '1em';
    
    var col;
    var toHighlight;
    
        
    for (var i = 0; i < columnValues.length; i++) {
        col = document.createElement('td');
        col.innerHTML = columnValues[i].value;
        
	highlightClassName = className;
        if (highlightCellOnly) {
            toHighlight = col;
	    if (columnValues[i].className)
		highlightClassName = columnValues[i].className;
	    else
	        highlightClassName = className;
	}
        else
            toHighlight = row;
	            
        if (columnValues[i].className) {
            col.className = columnValues[i].className;
        }
        else {
            if (this._columnDetails[i]) {
                col.className = this._columnDetails[i].className;
            }
        }
        
	var mouseOverFunction = function(e, style) {
            return function() {
                e.className = style;
            }
        }(toHighlight, highlightClassName + 'Hover' + evenOdd);
	
        var mouseOutFunction = function(e, style) {
            return function() {
                e.className = style;
            }
        }(toHighlight, highlightClassName + evenOdd);
                
        if (columnValues[i].colSpan) {
            col.setAttribute("colSpan", columnValues[i].colSpan);
        }
        
        if (columnValues[i].clickFunction) {
            colClickFunction = columnValues[i].clickFunction;
        }
	else {
	    colClickFunction = clickFunction;
	}
        
        if (colClickFunction) {
            col.onclick = colClickFunction;
            col.style.cursor = 'pointer';
            col.onmouseover = mouseOverFunction;
            col.onmouseout = mouseOutFunction;
        }
        
        row.appendChild(col);
    } 
    this._tableBodyDiv.appendChild(row);
    return row
}    

Exit66Table.prototype.addToParent = function(parent) {
    parent.appendChild(this._baseDiv);
}

Exit66Table.prototype.setTableVisibility = function(visibility) {
    if (visibility) {
        this._baseDiv.style.display = 'block'
    }
    else {
        this._baseDiv.style.display = 'none';
    }
}

Exit66Table.prototype.getTableVisibility = function() {
    var visibility = (this._baseDiv.style.display == 'block');
    return visibility;
}

Exit66Table.prototype.toggleVisibility = function() {
    this.setTableVisibility(!this.getTableVisibility());
}

Exit66Table.prototype.getElement = function() {
    return this._baseDiv;
}

Exit66Table.prototype.getRowParent = function() {
    return this._tableBodyDiv;
}

Exit66Table.prototype.removeFromParent = function() {
    if (this._baseDiv.parentNode)
        this._baseDiv.parentNode.removeChild(this._baseDiv);
}

